package com.example.springbootsfzy.controller.lishenao;

import com.example.springbootsfzy.domain.FieldsOfExcellence;
import com.example.springbootsfzy.service.lishenao.Fields_of_excellenceService;
import com.example.springbootsfzy.util.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

//擅长领域表
//操作人员:李深奥
//操作步骤:增删改查
@RestController
@CrossOrigin
public class Fields_of_excellenceController {
    @Autowired
    private Fields_of_excellenceService fieldsOfExcellenceService;
    //根据id查询擅长领域
    @GetMapping("/selectByPrimaryKey")
    public R selectByPrimaryKey(Long id){
        return R.ok(fieldsOfExcellenceService.selectByPrimaryKey(id));
    }
    //根据id删除擅长领域
    @DeleteMapping("/deleteByPrimaryKey")
    public R deleteByPrimaryKey(Long id){
        int i = fieldsOfExcellenceService.deleteByPrimaryKey(id);
        if (i>0){
            return R.ok("删除成功");
        }else {
            return R.error("删除失败");
        }
    }
    //新增擅长领域
    @PostMapping("/insert")
    public R insert(@RequestBody FieldsOfExcellence record){
        int i = fieldsOfExcellenceService.insert(record);
        if (i>0){
            return R.ok("新增成功");
        }else {
            return R.error("新增失败");
        }
    }
    //修改擅长领域
    @PutMapping ("/updateByPrimaryKey")
    public R updateByPrimaryKey(@RequestBody FieldsOfExcellence record){
        int i = fieldsOfExcellenceService.updateByPrimaryKey(record);
        if (i>0){
            return R.ok("修改成功");
        }else {
            return R.error("修改失败");
        }
    }
    /**
     * 查询所有擅长领域
     */
    @GetMapping("/getFields")
    @ResponseBody
    public List<String> getFields(){
        return fieldsOfExcellenceService.getFields();
    }
}
